package com.dragon.modules.yuegou.service.impl.member;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dragon.modules.yuegou.entity.member.PtTurntablePrizeEntity;
import com.dragon.modules.yuegou.mapper.member.PtTurntablePrizeMapper;
import com.dragon.modules.yuegou.service.member.PtTurntablePrizeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.stereotype.Service;

/**
 * 大转盘奖品 服务实现
 *
 * @author pbuilder generated
 * @date 2021-12-16 19:39:42
 * @version 2.0
 */
@Slf4j
@Service("memPtTurntablePrizeService")
public class PtTurntablePrizeServiceImpl
		extends ServiceImpl<PtTurntablePrizeMapper, PtTurntablePrizeEntity>
		implements PtTurntablePrizeService {

	protected static final String PT_TURNTABLE_PRIZE_CACHE_NAME = "ptTurntablePrize";

	private Cache ptTurntablePrizeCache;

	@Autowired
	public void setPtTurntablePrizeCacheManager(CacheManager cacheManager) {
		this.ptTurntablePrizeCache = cacheManager.getCache(PT_TURNTABLE_PRIZE_CACHE_NAME);
	}

	@Override
	public void setPrizeFlag(String memberId) {
		try {
			ptTurntablePrizeCache.put(memberId, "true");
		} catch (Exception e) {
			log.info("设置红点缓存出错" + e.getMessage());
		}
	}

	@Override
	public boolean getPrizeFlag(String memberId) {
        Cache.ValueWrapper exist = ptTurntablePrizeCache.get(memberId);
        return (exist != null && exist.get() != null);
	}

	@Override
	public void removePrizeFlag(String memberId) {
		try {
			ptTurntablePrizeCache.put(memberId, null);
		} catch (Exception e) {
			log.info("设置红点缓存出错" + e.getMessage());
		}
	}

}